from sqlalchemy import *
from models.baseModel import BaseModel
from utils.baseUtil import DATETIME_FORMAT_STR


class PageTree(BaseModel):
    """
    页面树结构表
    @author xyd-wupeng
    """
    __tablename__ = 'page_tree'

    id = Column(Integer, primary_key=True, index=True, unique=True)
    title_name = Column(String(255), nullable=False)
    parent_title_id = Column(String(255), nullable=False)
    page_url = Column(String(4095), nullable=False)
    page_code = Column(String(255), nullable=False)
    created_at = Column(DateTime(), default=DATETIME_FORMAT_STR, onupdate=DATETIME_FORMAT_STR)
    updated_at = Column(DateTime(), default=DATETIME_FORMAT_STR, onupdate=DATETIME_FORMAT_STR)

    def to_json(self):
        return {
            'id': self.id,
            'username': self.name,
            'name': self.name
        }